﻿using System.Linq;
using System.Web.Mvc;
using Omu.Awesome.Mvc;
using Omu.AwesomeDemo.Core.Model;
using Omu.AwesomeDemo.Core.Repository;

namespace Omu.AwesomeDemo.WebUI.Controllers
{
    public class ShowAutocompleteController : Controller
    {
        private readonly IRepo<Show> repo;

        public ShowAutocompleteController(IRepo<Show> repo)
        {
            this.repo = repo;
        }

        public ActionResult Search(string searchText, int maxResults)
        {
            return Json(repo.GetAll().Select(o => new IdTextItem {Id = o.Id, Text = o.Name}).Take(maxResults));
        }
    }
}